#include "TDynamicArray.h"

TDynamicArray::TDynamicArray():size(0),capacity(15)
{
    a = new ElementType[this->capacity];
}

TDynamicArray::~TDynamicArray()
{
    delete []a;
}

TDynamicArray::TDynamicArray(const TDynamicArray &d)
{
    this->size = d.size;
    this->capacity = d.capacity;
    this->a = new ElementType[this->capacity];
    for(int i = 0; i < size; i++)
    {
        this->a[i] = d.a[i];
    }
}

TDynamicArray &TDynamicArray::operator=(const TDynamicArray &d)
{
    delete[]a;
    this->size = d.size;
    this->capacity = d.capacity;
    this->a = new ElementType[this->capacity];
    for(int i = 0; i < size; i++)
    {
        this->a[i] = d.a[i];
    }
    return *this;
}

void TDynamicArray::Resize(ElementType newCapacity)
{
    this->size = size > newCapacity ? newCapacity : size;
    ElementType * newP = new ElementType[newCapacity];
    for(int i = 0; i < size; i++)
    {
        newP[i] = a[i];
    }
    delete []a;
    this->a = newP;
    
}

void TDynamicArray::InsertTail(ElementType element)
{
    
}
